package com.youdianstar.app.ui.help

import androidx.lifecycle.viewModelScope

import com.youdianstar.app.entity.FeedbackReq
import com.youdianstar.app.support.ApiRepository
import com.youdianstar.app.common.base.BaseViewModel
import com.youdianstar.app.common.entity.FileUpResult
import com.youdianstar.app.common.event.NetStateLiveData
import kotlinx.coroutines.launch


/**
 * File: FeedbackViewModel
 * Author: 82149 Create: 2021/11/18 19:39
 * Changes (from 2021/11/18)
 * --------------------------------------------------
 * description:
 * ---------------------------------------------------
 *
 */
class FeedbackViewModel(private val repo: ApiRepository) : BaseViewModel() {
    val fileUpLoadLiveData = NetStateLiveData<FileUpResult>()

    val fileDeleteLiveData = NetStateLiveData<Any>()

    /*上传图片*/
    fun upLoadImage(path: String){
        showLoading()
        viewModelScope.launch {
            repo.upLoadImage(path,fileUpLoadLiveData)
        }
    }

    /**删除服务端图片*/
    fun deleteImage(url:String){
        viewModelScope.launch {
            repo.deleteImage(url,fileDeleteLiveData)
        }
    }

    val reportResultLiveData = NetStateLiveData<Any>()

    /**普通反馈接口*/
    fun reportFeedback(req:FeedbackReq){
        showLoading()
        viewModelScope.launch {
            repo.reportFeedback(req,reportResultLiveData)
        }
    }

}